package com.ruipengkj.model;

import java.util.List;
import java.util.Vector;

import javax.swing.table.AbstractTableModel;

import com.ruipengkj.bean.TShopCharge;

public class MemberQueryShopChargeModel extends AbstractTableModel{
	private static final long serialVersionUID = 1L;
	private Vector<List<Object>> rowdatas = new Vector<List<Object>>();
	private Vector<String> columns = new Vector<String>();
	public MemberQueryShopChargeModel(){
		//columns.add("充值编号");
		columns.add("金额");
		columns.add("赠送金额");
		columns.add("赠送类型");
		columns.add("操作人");
		columns.add("是否有效");
		columns.add("操作时间");
		columns.add("开始时间");
		columns.add("结束时间");
	}
	/**
	 * 
	@Override
	public Class<?> getColumnClass(int columnIndex) {
		switch(columnIndex) {
		case 6:
		case 7:
			return Double.class;
		}
		return super.getColumnClass(columnIndex);
	}
	 */
	/**
	 * 返回列数
	 */
	@Override
	public int getColumnCount() {
		// TODO Auto-generated method stub
		return columns.size();
	}
	/**
	 * 返回行数
	 */
	@Override
	public int getRowCount() {
		// TODO Auto-generated method stub
		return rowdatas.size();
	}
	/**
	 * 获取单元格的值
	 */
	@Override
	public Object getValueAt(int row, int column) {
		// TODO Auto-generated method stub
		return ((Vector) rowdatas.get(row)).get(column+1);
	}
	/**
	 * 获取列名
	 * @param column
	 * @return
	 */
	public String getColumnName(int column){
		return (String)columns.get(column);
		
	}
	// 设置单元格是否可编辑
	public boolean isCellEditable(int rowIndex, int columnIndex) {
		return false;
	}
	public void removeData(int row) {
		rowdatas.remove(row);
	}

	// 设置单元格的值
	public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
		// 取出对应的记录
		Vector rowdata = (Vector) rowdatas.get(rowIndex);
		// 删除原来的值
		rowdata.remove(columnIndex);
		// 添加用户新修改的值
		rowdata.add(columnIndex, aValue);
	}
	
	public void setRowData(List<TShopCharge> tShopChargeList) {
		rowdatas.clear();
		if (tShopChargeList != null && tShopChargeList.size() != 0) {
			for (int i = 0; i < tShopChargeList.size(); i++) {
				TShopCharge tShopCharge = tShopChargeList.get(i);
				List<Object> row = new Vector<Object>();
				row.add(tShopCharge.getChargeID());
				row.add(tShopCharge.getAMount());
				row.add(tShopCharge.getGiftAmount());
				if(tShopCharge.getType().equals("1")){
					row.add("满就送");
				}else if(tShopCharge.getType().equals("2")){
					row.add("放大率");
				}
				row.add(tShopCharge.getOperator());
				if(tShopCharge.isIsValid()){
					row.add("有效");
				}else{
					row.add("失效");
				}
				
				row.add(tShopCharge.getHappenTime());
				row.add(tShopCharge.getStartTime());
				row.add(tShopCharge.getEndTime());
				rowdatas.add(row);
			}
		}
	}
	public void clear() {
		rowdatas.clear();
		
	}
}
